/*
 * generate by table-builder.Don't modify it
 */
using IQIGame.Onigao.Framework.Serialization;
using IQIGame.Onigao.GamePlay;
using System.Collections.Generic;


namespace CfgTable
{
    public partial class TbCfgGmCmd
    {
        private readonly Dictionary<int, CfgGmCmd> _dataMap;
        private readonly List<CfgGmCmd> _dataList;


        public TbCfgGmCmd(ByteBuf _buf)
        {
            //first read common data
            _TbCommonGmCmd _commonData = null;
            var commonSize = _buf.ReadSize();
            if (commonSize > 0)
            {
                _commonData = new _TbCommonGmCmd(_buf);
            }

            //then read row data
            var size = _buf.ReadSize();
            _dataMap = new Dictionary<int, CfgGmCmd>(size * 3 / 2);
            _dataList = new List<CfgGmCmd>(size);

            for (int i = 0; i < size; i++)
            {
                CfgGmCmd _v;
                _v = CfgGmCmd.DeserializeCfgGmCmd(_buf, _commonData);
                _dataList.Add(_v);
                _dataMap.Add(_v.Id, _v);
            }

            // read extra fields 

            PostInit();
        }

        public IReadOnlyDictionary<int, CfgGmCmd> DataMap => _dataMap;
        public IReadOnlyList<CfgGmCmd> DataList => _dataList;

        public CfgGmCmd Get(int key)
        {
            if (_dataMap.TryGetValue(key, out var v))
            {
                return v;
            }
            IQIGame.Onigao.Framework.LogGame.LogError("[TbCfgGmCmd] config not found,id:" + key.ToString());

            return null;
        }

        public CfgGmCmd GetWithoutError(int key) => _dataMap.TryGetValue(key, out var v) ? v : null;

        /// <summary>
        /// table data file
        /// </summary>
        public static string TableFileName { get; } = "gmcmd";

        /// <summary>
        /// load table function
        /// </summary>
        public static TbCfgGmCmd LoadFromFunc(System.Func<string, ByteBuf> loadFunc)
        {
            return new TbCfgGmCmd(loadFunc(TableFileName));
        }

        /// <summary>
        /// post process table
        /// </summary>
        partial void PostInit();

    }

    public partial class CfgGmCmd
    {
        private CfgGmCmd(ByteBuf _buf, _TbCommonGmCmd _commonData)
        {
            Id = _buf.ReadInt();
            Type = _buf.ReadInt();
            { int dataIndex = _buf.ReadInt() - 1; TypeName = _commonData._field0[dataIndex]; }
            SubType = _buf.ReadInt();
            { int dataIndex = _buf.ReadInt() - 1; SubTypeName = _commonData._field1[dataIndex]; }
            { int dataIndex = _buf.ReadInt() - 1; Name = _commonData._field2[dataIndex]; }
            { int dataIndex = _buf.ReadInt() - 1; Cmd = _commonData._field3[dataIndex]; }
            { int dataIndex = _buf.ReadInt() - 1; DefaultParam = _commonData._field4[dataIndex]; }

            PostInit();
        }

        internal static CfgGmCmd DeserializeCfgGmCmd(ByteBuf _buf, _TbCommonGmCmd _commonData)
        {
            return new CfgGmCmd(_buf, _commonData);
        }

        /// <summary>
        /// major key
        /// </summary>
        public int Id { get; private set; }

        /// <summary>
        /// 指令类型
        /// </summary>
        public int Type { get; private set; }
        /// <summary>
        /// 类型名
        /// </summary>
        public string TypeName { get; private set; }
        /// <summary>
        /// 子类型
        /// </summary>
        public int SubType { get; private set; }
        /// <summary>
        /// 子类型名
        /// </summary>
        public string SubTypeName { get; private set; }
        /// <summary>
        /// 指令名字
        /// </summary>
        public string Name { get; private set; }
        /// <summary>
        /// 指令内容
        /// </summary>
        public string Cmd { get; private set; }
        /// <summary>
        /// 默认参数
        /// </summary>
        public string DefaultParam { get; private set; }


        /// <summary>
        /// post process table
        /// </summary>
        partial void PostInit();
    }

    /// <summary>
    /// internal common data.Optimize memory
    /// </summary>
    internal class _TbCommonGmCmd
    {

        internal IReadOnlyList<string> _field0 { get; private set; }
        internal IReadOnlyList<string> _field1 { get; private set; }
        internal IReadOnlyList<string> _field2 { get; private set; }
        internal IReadOnlyList<string> _field3 { get; private set; }
        internal IReadOnlyList<string> _field4 { get; private set; }
        internal _TbCommonGmCmd(ByteBuf _buf)
        {
            { int __n0 = _buf.ReadSize(); var __f0 = new string[__n0]; _field0 = __f0; for (var __i0 = 0 ; __i0 < __n0 ; __i0++ ){ string __v0; __v0 = _buf.ReadString(); __f0[__i0] = __v0;} }
            { int __n0 = _buf.ReadSize(); var __f0 = new string[__n0]; _field1 = __f0; for (var __i0 = 0 ; __i0 < __n0 ; __i0++ ){ string __v0; __v0 = _buf.ReadString(); __f0[__i0] = __v0;} }
            { int __n0 = _buf.ReadSize(); var __f0 = new string[__n0]; _field2 = __f0; for (var __i0 = 0 ; __i0 < __n0 ; __i0++ ){ string __v0; __v0 = _buf.ReadString(); __f0[__i0] = __v0;} }
            { int __n0 = _buf.ReadSize(); var __f0 = new string[__n0]; _field3 = __f0; for (var __i0 = 0 ; __i0 < __n0 ; __i0++ ){ string __v0; __v0 = _buf.ReadString(); __f0[__i0] = __v0;} }
            { int __n0 = _buf.ReadSize(); var __f0 = new string[__n0]; _field4 = __f0; for (var __i0 = 0 ; __i0 < __n0 ; __i0++ ){ string __v0; __v0 = _buf.ReadString(); __f0[__i0] = __v0;} }
        }

    }
}
